package cn.smbms.interceptor;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import cn.smbms.dao.RoleMapper;
import cn.smbms.pojo.Permission;

public class CommonInterceptor extends HandlerInterceptorAdapter {
	
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		//User user = (User)request.getSession().getAttribute(Constants.USER_SESSION);
		WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext());
		RoleMapper roleMapper = (RoleMapper)webApplicationContext.getBean("roleMapper");
		List<Permission> permList = roleMapper.getPermissionByRoleId(1);
		request.setAttribute("permList", permList);
		return true;
	}

}
